<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="${namespace}">
  <resultMap type="${className}" id="${beanName}">
<#list properties as p>
    <result property="${p.name}" column="${p.columnName}" />
</#list>
  </resultMap>

	<insert id="insert" parameterType="${className}" 
	useGeneratedKeys="true" keyProperty="${id}">
    	insert into `${tableName}`(
    	<trim prefixOverrides=",">
    	<#list properties as p>
    	<#if p.name==id>
    		<if test="true">
    			,`${columnId}`
    		</if>
    	<#else>
	    	<if test="${p.name} != null">
	    		,`${p.columnName}`
	    	</if>
    	</#if>
    	</#list>
    	</trim>
    	) values(
		<trim prefixOverrides=",">
		<#list properties as p>
		<#if p.name==id>
    		<if test="true">
    			,#${l}${id}${r}
    		</if>
    	<#else>
	    	<if test="${p.name} != null">
    			,#${l}${p.name}${r}
    		</if>
    	</#if>
    	</#list>
    	</trim>
    	)
	</insert>
	<update id="update" parameterType="${className}">
		update `${tableName}` 
		<trim prefix="set" prefixOverrides=","> 
			<#list properties as p>
				<#if "${p.name}"!="${id}">
					<if test="${p.name} !=null">
						,`${p.columnName}` = #${l}${p.name}${r}
					</if>
				</#if>
			</#list>
		</trim>
		,`update_time` = now()
		where `${columnId}` = #${l}${id}${r}
	</update>
	<select id="findAll" parameterType="${className}" resultMap="${beanName}">
		select * from `${tableName}`
	</select>
	<select id="findById" parameterType="java.lang.Long" resultMap="${beanName}">
		select * from `${tableName}` where ${columnId} = #${l}${id}${r}
	</select>
	<delete id="delete" parameterType="java.lang.Long">
		delete from `${tableName}` where `${columnId}` = #${l}id${r}
	</delete>	
	<select id="find" parameterType="${className}" resultMap="${beanName}">
		select * from `${tableName}`
		<where>
			<#list properties as p>
				<if test="${p.name} !=null">
					and `${p.columnName}` = #${l}${p.name}${r} 
				</if>
			</#list>
		</where>
	</select>
	<select id="findPage" resultMap="${beanName}" parameterType="${criteria}">
		select * from `${tableName}`
		<where>
			<#list properties as p>
				<if test="${p.name} !=null">
					and `${p.columnName}` = #${l}${p.name}${r} 
				</if>
			</#list>
		</where>
		limit #${l}offset${r},#${l}limit${r}
	</select>
	<select id="getCount" parameterType="${criteria}" resultType="java.lang.Integer">
		select count(`${columnId}`) from `${tableName}`
		<where>
			<#list properties as p>
				<if test="${p.name} !=null">
					and `${p.columnName}` = #${l}${p.name}${r} 
				</if>
			</#list>
		</where>
	</select>
	<!-- 自定义的查询语句写在下方 -->
	
</mapper>